package TankGame;

/**
 * @author 王艺锡
 * @version 1.0
 */
//编写子弹射击的线程
public class Shot implements Runnable{
    int x;
    int y;
    int direct;
    int speed = 10;
    boolean isLive = true;

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (true) {

            //子弹休眠
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //子弹方向
            switch (direct) {
                case 0://向上
                    y -= speed;
                    break;
                case 1://向右
                    x += speed;
                    break;
                case 2://向下
                    y += speed;
                    break;
                case 3://向左
                    x -= speed;
                    break;
            }

            if(!(x>=0 && x <=1000 && y >= 0 && y <=750 && isLive)){
                isLive = false;
                break;
            }
            //System.out.println("x=" + x + "y=" + y);
        }
    }
}
